package fsu.cs.cis5930;

import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;

public class FakeApp extends GraphicsActivity {
	    
	static Display display;
	
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(new GIFView(this));
			Log.d("FakeApp", "Starting server...");
			startService(new Intent(this, ServerService.class ));
			display = getWindowManager().getDefaultDisplay();
		}
	    
	    private static class GIFView extends View{
	    	
	    	Movie movie;
	    	InputStream is=null;
	    	long moviestart;
	    	
			public GIFView(Context context) {
				super(context);
				is=context.getResources().openRawResource(R.drawable.poptartcat);
				movie=Movie.decodeStream(is);
				
			//	BitmapFactory.Options opts = new BitmapFactory.Options();
			//	opts.inJustDecodeBounds = true;    // this will request the bm
		       // opts.inSampleSize = 10;   
				//movie=Movie.decodeFile("C:\\cartoon.gif");
			}
			
	    	@Override
	    	protected void onDraw(Canvas canvas) {
	    		canvas.drawColor(0xFFCCCCCC);
	    		super.onDraw(canvas);
	    		long now=android.os.SystemClock.uptimeMillis();
	    		 if (moviestart == 0) {   // first time
	                 moviestart = now;
	                 
	             }
	    		 
	    		
	    		 int relTime = (int)((now - moviestart) % movie.duration()) ;
	    		 
	             movie.setTime(relTime);
	             
	             int width = display.getWidth();
	             int height = display.getHeight();
	             
	             movie.draw(canvas,55,50);
	             this.invalidate();
	    	}
	    }
	}
	

